#define _CRT_SECURE_NO_WARNINGS
#include"stack.h"
void STInit(ST* ps)
{
	assert(ps);
	ps->a = NULL;
	ps->top = ps->capacity = 0;
}
void STPush(ST* ps, STDataType x)
{
	assert(ps);
	if (ps->top == ps->capacity) {
		size_t newCapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		STDataType* temp = (STDataType*)realloc(ps->a, sizeof(STDataType) * newCapacity);
		if (temp == NULL) {
			perror("realloc failed!");
			exit(1);
		}
		ps->a = temp;
		ps->capacity = newCapacity; 
	}
	ps->a[ps->top++] = x;
}
bool STEmpty(ST* ps)
{
	assert(ps);
	return ps->top == 0;
}
void STPop(ST* ps)
{
	assert(!STEmpty(ps));
	ps->top--;
}
STDataType STTop(ST* ps)
{
	assert(!STEmpty(ps));
	int temp = ps->a[ps->top - 1];
	return temp;
}
int STSize(ST* ps)
{
	assert(ps);
	return ps->top;
}
void STDestroy(ST* ps)
{
	assert(ps);
	free(ps->a);
	ps->a = NULL;
	ps->capacity = ps->top = 0;
}